package com.leetcode;

/**
 * 125. 验证回文串
 * 双索引指针
 */
public class Solution125_2 {

    public boolean isPalindrome(String s) {
        int n = s.length();
        StringBuffer words = new StringBuffer(n);
        for (int i = 0; i < n; i++) {
            char ch = s.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                words.append(Character.toLowerCase(ch));
            }
        }
        String str = words.toString();
        int l = 0;
        int r = str.length() - 1;
        while (l <= r) {
            if (str.charAt(l) != str.charAt(r)) {
                return false;
            } else {
                l++;
                r--;
            }
        }
        return true;
    }

}
